package com.itcast.demo.mybatisinterceptor.controller;

import com.itcast.demo.datamask.annotation.User;
import com.itcast.demo.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mybatisInterceptor")
public class TestController {

    @Autowired
    private EmployeeMapper employeeMapper;

    @GetMapping("/users")
    public List<User> getUsers(@RequestParam(defaultValue = "1") int page,
                               @RequestParam(defaultValue = "10") int size) {
        int offset = (page - 1) * size;
//        int limit = Math.min(size, 10000); // 确保limit不超过1000
        int limit = size;
        return employeeMapper.selectUsers(offset, limit);
    }
}
